from django.db import models
from django.conf import settings

class Todo(models.Model):
    """待办事项模型"""
    STATUS_CHOICES = (
        ('pending', '待完成'),
        ('completed', '已完成'),
    )
    PRIORITY_CHOICES = (
        ('low', '低'),
        ('medium', '中'),
        ('high', '高'),
    )

    title = models.CharField(max_length=100, verbose_name='标题')
    description = models.TextField(blank=True, verbose_name='描述')
    status = models.CharField(max_length=10, choices=STATUS_CHOICES, default='pending', verbose_name='状态')
    priority = models.CharField(max_length=10, choices=PRIORITY_CHOICES, default='medium', verbose_name='优先级')
    due_date = models.DateField(null=True, blank=True, verbose_name='截止日期')
    user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, verbose_name='用户')
    created_at = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    updated_at = models.DateTimeField(auto_now=True, verbose_name='更新时间')

    class Meta:
        verbose_name = '待办事项'
        verbose_name_plural = verbose_name
        ordering = ['-created_at']

    def __str__(self):
        return self.title
